import dayjs from 'dayjs'

let instance
export default {
  type: 'crud',
  autoRequest: false,
  border: true,
  api: {
    url: `/adjustmentBill/info`,
    method: 'POST',
    responseData: '',
    data: {
      billType: '02',
      bussType: 'API_COST'
    }
  },
  onMounted(e) {
    instance = e.instance
  },
  querys: [
    {
      type: 'select',
      prop: 'suppliers',
      multiple: true,
      collapseTags: true,
      checkAll: true,
      label: '合作方',
      placeholder: '请选择合作方',
      api: {
        url: '/supplier/info/selectDifSupplierInfo?status=0&bussType=API_COST',
        responseAdaptor: (response) => {
          response.data = response.data.map((item) => ({
            label: item,
            value: item
          }))
          return response
        }
      },
      event: {
        loaded: (data) => {
          if (data && data.length) {
            instance.setupState.excuteQueryFn('updateDefaultValue', {
              suppliers: [data[0].value]
            })
            instance.setupState.queryEvent()
          }
        }
      }
    },
    {
      type: 'datePicker',
      prop: 'attribMonth',
      label: '归属月',
      placeholder: '请选择归属月',
      defaultValue: dayjs().format('YYYYMM'),
      'value-format': 'YYYYMM',
      reflectAttr: {
        type: 'month'
      }
    },
    {
      type: 'datePicker',
      prop: 'approveMonth',
      label: '审批月',
      placeholder: '请选择审批月',
      defaultValue: dayjs().format('YYYYMM'),
      'value-format': 'YYYYMM',
      reflectAttr: {
        type: 'month'
      }
    },
    {
      type: 'select',
      prop: 'stepStatus',
      label: '状态',
      placeholder: '请选择状态',
      fieldNames: { label: 'dictLabel', value: 'dictValue' },
      api: '/system/dict/data/type/estimate_bill_status'
    }
  ],
  columns: [
    {
      title: '核算组织',
      field: 'stmAgent'
    },
    {
      title: '合作方',
      field: 'supplier'
    },
    {
      title: '归属月',
      field: 'attribMonth'
    },
    {
      title: '签约主体',
      field: 'stmAgent'
    },
    {
      title: '项目名称',
      field: 'projectInfo'
    },
    {
      title: '状态',
      field: 'stepStatus',
      slots: {
        default: {
          type: 'mapping',
          cache: true,
          value: '${stepStatus}',
          api: {
            url: '/system/dict/data/type/estimate_bill_status',
            responseAdaptor: (response) => {
              const data = response.data
              const map = {}
              data.forEach((item) => {
                map[item.dictValue] = item.dictLabel
              })
              return {
                data: map
              }
            }
          }
        }
      }
    },
    {
      title: '业务部门',
      field: 'department'
    },
    {
      title: '收款方',
      field: 'supplierReceive'
    },
    {
      title: '项目名称',
      field: 'projectInfo'
    },
    {
      title: '预估金额（元）',
      field: 'estimateFee'
    },
    {
      title: '实付成本（元）',
      field: 'payFee'
    },
    {
      title: '差异成本（元）',
      field: 'promotionFee'
    },
    {
      title: '操作',
      field: 'operation',
      body: {
        type: 'link',
        reflectAttr: { type: 'primary' },
        actionType: 'confirm',
        messageContent: '确定要上报吗？',
        refreshTable: true,
        api: {
          url: '/estimateBill/info/reportJd',
          data: {
            id: '${id}'
          },
          successMsg: '',
          method: 'POST'
        },
        body: '记账'
      }
    }
  ]
}
